package cn.hchaojie.snippets.event;

import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.LinearLayout;
import android.widget.TextView;

public class TestTouchEvent extends Activity {
	public static final String TAG = "TestTouchEventActivity";

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        MyLinearLayout layout = new MyLinearLayout(this);
        layout.setLayoutParams(new LinearLayout.LayoutParams(
        		LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
        
        MyTextView tv = new MyTextView(this);
        tv.setText("hello touch me.");
        
        
        layout.addView(tv, new LinearLayout.LayoutParams(
        		LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));
        setContentView(layout);
    }
    
    class MyLinearLayout extends LinearLayout {
		public MyLinearLayout(Context context) {
			super(context);
		}

		@Override
		public boolean onInterceptTouchEvent(MotionEvent ev) {			
			Log.v(TAG, "MyLinearLayout on InterceptTouch event. MotionEvent: " + ev.toString());
			return false;
		}

		@Override
		public boolean onTouchEvent(MotionEvent event) {
			Log.v(TAG, "MyLinearLayout on touch event. MotionEvent: " + event.toString());
			
			return true;
		}
    }
    
    class MyTextView extends TextView {
		public MyTextView(Context context) {
			super(context);
		}

		@Override
		public boolean onTouchEvent(MotionEvent event) {
			Log.v(TAG, "My Text on touch event. MotionEvent: " + event.toString());
			return false;
		}
    }
}